home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Set Text / Set Text of Text Field.js < prev   
Encoding:
Text File  |  1999-12-01  |  4.6 KB  |  143 lines

  1. // Copyright 1999 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS VARS *****************
  4.  
  5. var helpDoc = MM.HELP_behSetTextOfTextField;
  6.  
  7. //******************* BEHAVIOR FUNCTION **********************
  8.  
  9. //Passed a textfield name and a string, replaces textfield text.
  10.  
  11. function MM_setTextOfTextfield(objName,x,newText) { //v3.0
  12.   var obj = MM_findObj(objName); if (obj) obj.value = newText;
  13. }
  14.  
  15. document.VERSION_MM_setTextOfTextfield = 3.0; //define latest version number for behavior inspector
  16.  
  17. //******************* API **********************
  18.  
  19.  
  20. //Can be used with any tag and any event
  21.  
  22. function canAcceptBehavior(){
  23.   var retVal = false;
  24.   var nameArray = getAllObjectRefs("NS 4.0","INPUT/TEXT","TEXTAREA","INPUT/PASSWORD");
  25.   if (nameArray.length > 0) retVal = "onMouseOver,(onMouseOver),onClick,(onClick)";
  26.   return retVal;
  27. }
  28.  
  29.  
  30.  
  31. //Returns a Javascript function to be inserted in HTML head with script tags.
  32.  
  33. function behaviorFunction(){
  34.   return "MM_findObj,MM_setTextOfTextfield";
  35. }
  36.  
  37.  
  38.  
  39. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  40. //Calls escQuotes to find embedded quotes and precede them with \
  41.  
  42. function applyBehavior() {
  43.   var i,index,objNS,newlinePos,msgStr="",retVal="";
  44.   with (document.theForm) {
  45.     index = menu.selectedIndex;
  46.     objNS = escQuotes(document.MM_NS_REFS[index]); //get textfield name from list
  47.     msgStr = escExprStr(message.value,false);
  48.   }
  49.   if (objNS.indexOf(REF_UNNAMED) == 0) retVal = MSG_UnnamedTextfield;
  50.   else if (msgStr == null) retVal = MSG_BadBraces;
  51.   else {
  52.     objNS = getNameFromRef(objNS);
  53.     updateBehaviorFns("MM_findObj","MM_setTextOfTextfield");
  54.     retVal = "MM_setTextOfTextfield('"+objNS+"','','"+msgStr+"')";
  55.   }
  56.   return retVal
  57. }
  58.  
  59.  
  60.  
  61. //Passed the function call above, takes prior arguments and reloads the UI.
  62. //Removes any escape characters "\"
  63.  
  64. function inspectBehavior(fnStr){
  65.   var argArray,found,numTxtflds,i;
  66.   var objNS,objIE,startStr,endStr,msgStr;
  67.  
  68.   argArray = extractExprStr(fnStr);//get new list of textfields, text triplets
  69.   if (argArray.length == 3) { //3 args
  70.     //set textfield obj
  71.     objNS=argArray[0];
  72.     objIE=argArray[1];
  73.     found = false;
  74.     numTxtflds = document.MM_NS_REFS.length;
  75.     for (i=0; i<numTxtflds; i++){  //check if textfield is in menu
  76.       if (objNS==document.MM_NS_REFS[i] || objNS==getNameFromRef(document.MM_NS_REFS[i])) { //if textfield there
  77.         document.theForm.menu.selectedIndex = i;
  78.         found = true;
  79.         break;
  80.       }
  81.     }
  82.     if (!found) alert(errMsg(MSG_TextfieldNotFound,objNS));
  83.  
  84.     //set text, converting all string expressions to {expression} etc.
  85.     document.theForm.message.value = unescExprStr(argArray[2],false);
  86.   }
  87. }
  88.  
  89.  
  90.  
  91. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  92. //call arguments. This information is used by DW to fixup behavior args when the
  93. //document is moved or changed.
  94. //
  95. //It is passed an actual function call string generated by applyBehavior(), which
  96. //may have a variable list of arguments, and this should return a matching mask.
  97. //
  98. //The return values are:
  99. //  objName:  argument is simple object name, such as "textfield1"
  100. //  other...: argument is ignored
  101.  
  102. function identifyBehaviorArguments(fnCallStr) {
  103.   var argArray, retVal="", fullObjRef;;
  104.  
  105.   argArray = extractArgs(fnCallStr);
  106.   fullObjRef = (argArray[1].indexOf(".")!=-1);
  107.   if (argArray.length == 4) {
  108.     retVal = (fullObjRef)?"NS4.0ref,IE4.0ref,other" : "objName,other,other";
  109.   }
  110.   return retVal;
  111. }
  112.  
  113. //***************** LOCAL FUNCTIONS  ******************
  114.  
  115.  
  116. //Load up the textfields, set the insertion point
  117.  
  118. function initializeUI(){
  119.   var i, niceNameSrcArray, nameArray;
  120.  
  121.   document.MM_NS_REFS = getAllObjectRefs("NS 4.0","INPUT/TEXT","TEXTAREA","INPUT/PASSWORD");
  122.   document.MM_IE_REFS = getAllObjectRefs("IE 4.0","INPUT/TEXT","TEXTAREA","INPUT/PASSWORD");
  123.     //Search for unreferenceable objects. <DIV id="foo"> is IE only, <LAYER> is NS only.
  124.     //if REF_CANNOT found, return empty string, and use IE refs for nice namelist.
  125.     niceNameSrcArray = document.MM_NS_REFS;
  126.     for (i=0; i<document.MM_NS_REFS.length; i++) {
  127.         if (document.MM_IE_REFS[i].indexOf(REF_CANNOT) == 0) {
  128.             document.MM_IE_REFS[i] = ""; //blank it out
  129.         }
  130.         if (document.MM_NS_REFS[i].indexOf(REF_CANNOT) == 0) {
  131.             document.MM_NS_REFS[i] = ""; //blank it out
  132.             niceNameSrcArray = document.MM_IE_REFS; //use the IE list
  133.         }
  134.     }
  135.     nameArray = niceNames(niceNameSrcArray,TYPE_Text);  //get textfield names
  136.     with (document.theForm.menu) {
  137.         for (i=0; i<nameArray.length; i++) options[i]=new Option(nameArray[i]); //load menu
  138.         selectedIndex = 0;
  139.     }
  140.   document.theForm.message.focus(); //set focus on textbox
  141.   document.theForm.message.select(); //set insertion point into textbox
  142. }
  143.